package cn.org.guhao.practice.go.thread;

import cn.org.guhao.practice.go.service.WordFileThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;

public class CountWordThreadFactory implements ThreadFactory {

  private static final Logger logger = LoggerFactory.getLogger(CountWordThreadFactory.class);

  private AtomicLong atomicLong = new AtomicLong(0);

  @Override
  public Thread newThread(Runnable r) {
    long c = atomicLong.incrementAndGet();
    logger.info("工厂当前进程数:[{}]", c);
    return new WordFileThread(r,atomicLong);
  }

  public AtomicLong getAtomicLong() {
    return atomicLong;
  }
}
